home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3x / fam.z / fam
Encoding:
Text File  |  2002-10-03  |  20.3 KB  |  397 lines

  1.  
  2.  
  3.  
  4. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      fam - File Alteration Monitor (FAM) library routines
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<ffffaaaammmm....hhhh>>>>
  13.  
  14.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt FFFFAAAAMMMMOOOOppppeeeennnn((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn**** ffffcccc))));;;;
  15.  
  16.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt FFFFAAAAMMMMCCCClllloooosssseeee((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn**** ffffcccc))));;;;
  17.  
  18.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt FFFFAAAAMMMMMMMMoooonnnniiiittttoooorrrrDDDDiiiirrrreeeeccccttttoooorrrryyyy((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,,
  19.                                     cccchhhhaaaarrrr ****ffffiiiilllleeeennnnaaaammmmeeee,,,,
  20.                                     FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt**** ffffrrrr,,,,
  21.                                     vvvvooooiiiidddd**** uuuusssseeeerrrrDDDDaaaattttaaaa))));;;;
  22.  
  23.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt FFFFAAAAMMMMMMMMoooonnnniiiittttoooorrrrFFFFiiiilllleeee((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,,
  24.                                cccchhhhaaaarrrr ****ffffiiiilllleeeennnnaaaammmmeeee,,,,
  25.                                FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt**** ffffrrrr,,,,
  26.                                vvvvooooiiiidddd**** uuuusssseeeerrrrDDDDaaaattttaaaa))));;;;
  27.  
  28.      iiiinnnntttt FFFFAAAAMMMMSSSSuuuussssppppeeeennnnddddMMMMoooonnnniiiittttoooorrrr((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,, FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt ****ffffrrrr))));;;;
  29.  
  30.      iiiinnnntttt FFFFAAAAMMMMRRRReeeessssuuuummmmeeeeMMMMoooonnnniiiittttoooorrrr((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,, FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt ****ffffrrrr))));;;;
  31.  
  32.      iiiinnnntttt FFFFAAAAMMMMCCCCaaaannnncccceeeellllMMMMoooonnnniiiittttoooorrrr((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,, FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt ****ffffrrrr))));;;;
  33.  
  34.      iiiinnnntttt FFFFAAAAMMMMNNNNeeeexxxxttttEEEEvvvveeeennnntttt((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn ****ffffcccc,,,, FFFFAAAAMMMMEEEEvvvveeeennnntttt ****ffffeeee))));;;;
  35.  
  36.      iiiinnnntttt FFFFAAAAMMMMPPPPeeeennnnddddiiiinnnngggg((((FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn**** ffffcccc))));;;;
  37.  
  38.      ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt {{{{
  39.          iiiinnnntttt ffffdddd;;;;
  40.      }}}} FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn;;;;
  41.  
  42.      ####ddddeeeeffffiiiinnnneeee FFFFAAAAMMMMCCCCOOOONNNNNNNNEEEECCCCTTTTIIIIOOOONNNN____GGGGEEEETTTTFFFFDDDD((((ffffcccc))))      ((((ffffcccc---->>>>ffffdddd))))
  43.  
  44.      ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt {{{{
  45.          iiiinnnntttt rrrreeeeqqqqnnnnuuuummmm;;;;
  46.      }}}} FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt;;;;
  47.  
  48.      eeeennnnuuuummmm FFFFAAAAMMMMCCCCooooddddeeeessss {{{{ FFFFAAAAMMMMCCCChhhhaaaannnnggggeeeedddd====1111,,,, FFFFAAAAMMMMDDDDeeeelllleeeetttteeeedddd====2222,,,, FFFFAAAAMMMMSSSSttttaaaarrrrttttEEEExxxxeeeeccccuuuuttttiiiinnnngggg====3333,,,,
  49.          FFFFAAAAMMMMSSSSttttooooppppEEEExxxxeeeeccccuuuuttttiiiinnnngggg====4444,,,, FFFFAAAAMMMMCCCCrrrreeeeaaaatttteeeedddd====5555,,,, FFFFAAAAMMMMMMMMoooovvvveeeedddd====6666,,,, FFFFAAAAMMMMAAAAcccckkkknnnnoooowwwwlllleeeeddddggggeeee====7777,,,,
  50.          FFFFAAAAMMMMEEEExxxxiiiissssttttssss====8888,,,, FFFFAAAAMMMMEEEEnnnnddddEEEExxxxiiiisssstttt====9999 }}}};;;;
  51.  
  52.      ttttyyyyppppeeeeddddeeeeffff ssssttttrrrruuuucccctttt {{{{
  53.          FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn**** ffffcccc;;;;
  54.          FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt ffffrrrr;;;;
  55.          cccchhhhaaaarrrr hhhhoooossssttttnnnnaaaammmmeeee[[[[MMMMAAAAXXXXHHHHOOOOSSSSTTTTNNNNAAAAMMMMEEEELLLLEEEENNNN]]]];;;;
  56.          cccchhhhaaaarrrr ffffiiiilllleeeennnnaaaammmmeeee[[[[NNNNAAAAMMMMEEEE____MMMMAAAAXXXX]]]];;;;
  57.          vvvvooooiiiidddd ****uuuusssseeeerrrrddddaaaattttaaaa;;;;
  58.          FFFFAAAAMMMMCCCCooooddddeeeessss ccccooooddddeeee;;;;
  59.      }}}} FFFFAAAAMMMMEEEEvvvveeeennnntttt;;;;
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  71.  
  72.  
  73.  
  74.      eeeexxxxtttteeeerrrrnnnn iiiinnnntttt FFFFAAAAMMMMEEEErrrrrrrrnnnnoooo;;;;
  75.  
  76.      eeeexxxxtttteeeerrrrnnnn cccchhhhaaaarrrr ****FFFFaaaammmmEEEErrrrrrrrlllliiiisssstttt[[[[]]]];;;;
  77.  
  78. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  79.      _F_A_M monitors files and directories, notifying interested applications of
  80.      changes.  Routines for communicating with the fam(1M) server process are
  81.      found in ``libfam.a'', which is loaded if the option ``-lfam'' is used
  82.      with cc(1) or ld(1).  The library ``libC.a'' (``-lC'') must also be
  83.      specified.
  84.  
  85.      An application calls routines described here to establish a list of files
  86.      for _f_a_m to monitor.  _F_a_m generates events on a socket to communicate with
  87.      the application.  The _f_a_m process is started when the first connection
  88.      from any application to it is opened.  It exits after all connections to
  89.      it have been closed.
  90.  
  91. UUUUSSSSIIIINNNNGGGG FFFFAAAAMMMM
  92.      Here are the steps required to use _F_A_M in an application:
  93.  
  94.      1.   Create a connection to _f_a_m by calling FAMOpen.  This routine will
  95.           pass back a FAMConnection structure used in all _f_a_m procedures.
  96.  
  97.      2.   Tell _f_a_m which files and directories to monitor by calling
  98.           FAMMonitorFile and FAMMonitorDirectory to express interest in files
  99.           and directories, respectively.
  100.  
  101.      3.   Select on the _f_a_m socket file descriptor and call FAMPending when
  102.           the _f_a_m socket is active, and FAMNextEvent when FAMPending indicates
  103.           that an event is available.  Alternatively, call FAMPending (or
  104.           FAMNextEvent) periodically to check the socket connection to _f_a_m to
  105.           see if any new information has arrived.  If there are no events
  106.           pending, FAMNextEvent blocks until an event occurs.
  107.  
  108.      4.   When the application is through monitoring a file or directory, it
  109.           should call FAMCancelMonitor.  If the application wants to
  110.           temporarily suspend monitoring of a file or directory, it may call
  111.           FAMSuspendMonitor.  When the application is ready to start
  112.           monitoring again, it calls FAMResumeMonitor.
  113.  
  114.      5.   Before the application exits, it should call FAMClose to free
  115.           resources associated with files still being monitored and to close
  116.           the connection to _f_a_m.
  117.  
  118. DDDDAAAATTTTAAAA SSSSTTTTRRRRUUUUCCCCTTTTUUUURRRREEEESSSS
  119.      TTTThhhheeee FFFFAAAAMMMMCCCCoooonnnnnnnneeeeccccttttiiiioooonnnn SSSSttttrrrruuuuccccttttuuuurrrreeee
  120.  
  121.      The FAMConnection data structure is created when opening a connection to
  122.      _F_A_M.  Subsequently it is passed into all _F_A_M procedures.  This structure
  123.      has all the information in it to communicate to _f_a_m.
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  137.  
  138.  
  139.  
  140.      Use the macro FAMCONNECTION_GETFD to access the file descriptor inside
  141.      the FAMConnection, rather than accessing it directly.
  142.  
  143.      TTTThhhheeee FFFFAAAAMMMMRRRReeeeqqqquuuueeeesssstttt SSSSttttrrrruuuuccccttttuuuurrrreeee
  144.  
  145.      When _f_a_m is called on to monitor a file, it passes back a FAMRequest
  146.      structure.  This structure uniquely identifies the request so that it may
  147.      be cancelled, using FAMCancelMonitor or suspended, using
  148.      FAMSuspendMonitor.
  149.  
  150.      TTTThhhheeee FFFFAAAAMMMMEEEEvvvveeeennnntttt SSSSttttrrrruuuuccccttttuuuurrrreeee
  151.  
  152.      Changes to files and directories are encoded in the FAMEvent structure.
  153.      The _c_o_d_e field of this structure contains one of the following
  154.      enumeration constants:
  155.  
  156.      FAMChanged
  157.               Some value which can be obtained with fstat(1) changed for a
  158.               file or directory being monitored.
  159.  
  160.      FAMDeleted
  161.               A file or directory being monitored was deleted or its name was
  162.               changed.  This event is also generated when monitoring starts on
  163.               a nonexistent file or directory.
  164.  
  165.      FAMStartExecuting
  166.               An executable file or shared library being monitored started
  167.               executing.  If multiple processes execute the same file, this
  168.               event only occurs when the first process starts.
  169.  
  170.      FAMStopExecuting
  171.               An executable file being monitored which was running finished.
  172.               If multiple processes from an executable are running, this event
  173.               is only generated when the last one finishes.
  174.  
  175.      FAMCreated
  176.               A file was created in a directory being monitored.  Note: this
  177.               event is only generated for files created directly in a
  178.               directory being monitored; subdirectories are not automatically
  179.               monitored.
  180.  
  181.      FAMMoved FAMMoved events never occur.  The name remains defined so that
  182.               programs that reference it will still compile.
  183.  
  184.      FAMAcknowledge
  185.               After a FAMCancelMonitor, _f_a_m generates a FAMAcknowledge event.
  186.               Also, if an invalid pathname is specified, _f_a_m  generates a
  187.               FAMAcknowledge event.
  188.  
  189.      FAMExists
  190.               When the application requests a file be monitored, _f_a_m generates
  191.               a FAMExists event for that file.  When the application requests
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  203.  
  204.  
  205.  
  206.               a directory be monitored, _f_a_m generates a FAMExists event for
  207.               that directory and every file directly contained in that
  208.               directory.
  209.  
  210.      FAMEndExist
  211.               When the application requests a file directory be monitored, a
  212.               series of FAMExists events is generated as described above.
  213.               After the last FAMExists message, _f_a_m generates a FAMEndExist
  214.               message.
  215.  
  216.      If a FAM event applies to a file or directory being monitored, the
  217.      FAMEvent's _f_i_l_e_n_a_m_e field contains the full pathname that was passed to
  218.      fam.  If an event applies to an entry in a monitored directory, the
  219.      _f_i_l_e_n_a_m_e field contains the relative path only.  For example, if the
  220.      directory /_u_s_r/_t_m_p/_x_y_z_z_y were monitored, and the file
  221.      /_u_s_r/_t_m_p/_x_y_z_z_y/_p_l_u_g_h  were deleted, a FAMDeleted event would be generated
  222.      containing "plugh" in _f_i_l_e_n_a_m_e.  If the directory itself were deleted,
  223.      _f_i_l_e_n_a_m_e would contain "/usr/tmp/xyzzy".
  224.  
  225. PPPPRRRROOOOCCCCEEEEDDDDUUUURRRREEEESSSS
  226.      FFFFAAAAMMMMOOOOppppeeeennnn,,,, FFFFAAAAMMMMCCCClllloooosssseeee
  227.  
  228.      The application opens a connection to _f_a_m by calling FAMOpen.  FAMOpen
  229.      initializes the FAMConnection structure passed in to it and returns 0 if
  230.      successful, otherwise -1.  The variable char* appName should be set to
  231.      the name of your application. The FAMConnection structure is passed to
  232.      all subsequent _F_A_M procedure calls.
  233.  
  234.      FAMClose frees resources associated with files still being monitored and
  235.      closes a _f_a_m connection.  It returns 0 if successful and -1 otherwise.
  236.  
  237.      FFFFAAAAMMMMMMMMoooonnnniiiittttoooorrrrDDDDiiiirrrreeeeccccttttoooorrrryyyy,,,, FFFFAAAAMMMMMMMMoooonnnniiiittttoooorrrrFFFFiiiilllleeee
  238.  
  239.      FAMMonitorDirectory and FAMMonitorFile tell _F_A_M to start monitoring a
  240.      directory or file, respectively.  The parameters to this function are a
  241.      FAMConnection (initialized by FAMOpen), a FAMRequest structure, a
  242.      filename and a user data pointer.  The FAMRequest structure is modified
  243.      to subsequently identify this request.  When the file or directory
  244.      changes, a _F_A_M event structure will be generated.  The application can
  245.      retrieve this structure by calling FAMNextEvent (see description under
  246.      FAMNextEvent).
  247.  
  248.      FAMMonitorDirectory monitors changes that happens to the contents of the
  249.      directory (as well as the directory file itself); FAMMonitorFile monitors
  250.      only what happens to a particular file.  Both routines return 0 if
  251.      successful and -1 otherwise.
  252.  
  253.      The filename argument must be a full pathname.
  254.  
  255.      FFFFAAAAMMMMSSSSuuuussssppppeeeennnnddddMMMMoooonnnniiiittttoooorrrr,,,, FFFFAAAAMMMMRRRReeeessssuuuummmmeeeeMMMMoooonnnniiiittttoooorrrr
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  269.  
  270.  
  271.  
  272.      FAMSuspendMonitor temporarily suspends monitoring of files or
  273.      directories.  This is useful when an application is not displaying
  274.      information about files, when it is iconified, for example.
  275.      FAMResumeMonitor signals _f_a_m to start monitoring the file or directory
  276.      again.  Changes which occur while monitoring is suspended are enqueued
  277.      and delivered when monitoring is resumed.
  278.  
  279.      Both of these routines take a FAMConnection and a FAMRequest structure.
  280.      The FAMRequest Structure is returned from the FAMMonitorFile or
  281.      FAMMonitorDirectory routines and return 0 if successful and -1 otherwise.
  282.  
  283.      Because fam runs as an asynchronous process, FAMNextEvent may return a
  284.      few events regarding a given request after that request has been
  285.      suspended.
  286.  
  287.      FFFFAAAAMMMMCCCCaaaannnncccceeeellllMMMMoooonnnniiiittttoooorrrr
  288.  
  289.      When an application is through monitoring a file or directory, it should
  290.      call FAMCancelMonitor.  This routine will signal _f_a_m not to monitor this
  291.      directory anymore.  The FAMRequest structure is returned from the
  292.      FAMMonitorFile or FAMMonitorDirectory routines.  FAMCancelMonitor returns
  293.      0 if successful and -1 otherwise.
  294.  
  295.      FFFFAAAAMMMMPPPPeeeennnnddddiiiinnnngggg,,,, FFFFAAAAMMMMNNNNeeeexxxxttttEEEEvvvveeeennnntttt
  296.  
  297.      FAMPending returns 1 if an event is waiting and 0 if no event is waiting.
  298.      It also returns 1 if an error has been encountered.  This routine returns
  299.      immediately to the caller.
  300.  
  301.      FAMNextEvent will get the next _F_A_M event.  If there are no _F_A_M events
  302.      waiting, then the calling application blocks until a _F_A_M event is
  303.      received.  If blocking is not desirable, call FAMPending before
  304.      FAMNextEvent, and only call FAMNextEvent when FAMPending says an event is
  305.      available.
  306.  
  307.      There are two ways to for applications to receive _F_A_M events:
  308.  
  309.      1. The Select approach - The application selects on the file
  310.          descriptor returned from FAMOpen, in the FAMConnection structure.
  311.          When this file descriptor becomes active, the application calls
  312.          FAMPending to determine whether a complete event is ready, and
  313.          FAMNextEvent to retrieve the pending _F_A_M event.
  314.  
  315.      2. The Polling approach - The application calls FAMPending
  316.          periodically (usually when the system is waiting for input).
  317.          When FAMPending returns 1, the application calls FAMNextEvent to
  318.          retrieve the pending _F_A_M  event.
  319.  
  320.      FAMNextEvent reads any information that is on the _f_a_m socket, and returns
  321.      it to the application in the form of a FAMEvent.
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. FFFFAAAAMMMM((((3333XXXX))))                                                                FFFFAAAAMMMM((((3333XXXX))))
  335.  
  336.  
  337.  
  338.      FAMNextEvent returns 1 if successful and -1 otherwise.
  339.  
  340.  
  341.  
  342. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  343.      fam(1M).
  344.  
  345. BBBBUUUUGGGGSSSS
  346.      The FAMMoved event is not currently supported.
  347.  
  348.      FAMNextEvent may not initialize the FAMEvent's filename field for
  349.      FAMEndExist and FAMAcknowledge events.  Use the request number to
  350.      determine the file or directory to which those events refer.
  351.  
  352.      FAMErrno and FamErrlist are not set when errors occur.
  353.  
  354.      When a shell script is run, notification is generated for the shell
  355.      executing the script, typically sh(1) or csh(1).
  356.  
  357.      Each process is limited to 1000 active requests at a time.
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.